<template>
    <div class="p-15 p-t-0">
        <div class="table-search" style="width: 100%">
            <el-row :gutter="20">

                <el-col :span="6">
                    <el-input v-model="input" @keyup.enter.native="keyDown($event)" placeholder="根据编码或名称检索" :maxlength="20" size="medium">
                        <template slot="prepend">
                            <el-button tabIndex="-1">成品信息</el-button>
                        </template>
                    </el-input>
                </el-col>
                <el-col :span="6">
                    <el-input v-model="material" @keyup.enter.native="keyDown($event)" placeholder="请输入原料名称" :maxlength="20" size="medium" >
                        <template slot="prepend">
                            <el-button tabIndex="-1">原料</el-button>
                        </template>
                    </el-input>
                </el-col>
                <el-col :span="6">
                    <div class="el-input el-input-group el-input-group--prepend">
                        <div class="el-input-group__prepend">
                            <el-button tabIndex="-1" size="medium">是否包含加工关系</el-button>
                        </div>
                        <el-select v-model="hasCosts" placeholder="请选择" size="medium" style="width:100%">
                            <el-option label="全部" value=""></el-option>
                            <el-option label="是" value="true"></el-option>
                            <el-option label="否" value="false"></el-option>
                        </el-select>
                    </div>
                </el-col>
                <el-col :span="6">
                    <el-button  class="btn-info"  icon="search" @click="search" size="medium">搜索</el-button>
                    <el-button  class="btn-warning" style="margin-left: 1px"  icon="setting" size="medium" @click="cleanSearch">重置</el-button>
                </el-col>
            </el-row>
        </div>

        <div class="table-padding p-t-15">
            <el-table
                 v-loading="loading"
                 :data="tableData"
                 :border="true"
                 style="width: 100%">
                <el-table-column
                   type="index"
                   width="50">
                 </el-table-column>

                <el-table-column
                        label="成品编码">
                    <template scope="scope">
                        <span>{{scope.row.no}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="成品名称">
                    <template scope="scope">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="库存单位">
                    <template scope="scope">
                        <span>{{scope.row.unit }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="规格">
                    <template scope="scope">
                        <span>{{scope.row.goods_spec}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="成本价">
                    <template scope="scope">
                        <span>{{scope.row.order_price_bom | money }}</span>
                    </template>
                </el-table-column>
                <el-table-column
                        label="操作" width="280">
                    <template scope="scope" >
                        <!--<router-link :to="'/orderRelationship/update?id='+scope.row.id+'&type=1'" v-if="scope.row.isCpunt>0">查看 |</router-link>-->
                            <el-button size="small" type="text" @click="router.push({path:'/orderRelationship/update?id='+scope.row.id+'&type=1'})" v-if="scope.row.isCpunt>0">查看 |</el-button>
                            <el-button size="small" type="text" @click="router.push({path:'/orderRelationship/add?id='+scope.row.id})" v-if="scope.row.isCpunt==0">添加加工关系 |</el-button>
                        <el-button size="small" type="text" @click="router.push({path:'/orderRelationship/update?id='+scope.row.id})" v-if="scope.row.isCpunt>0">编辑加工关系 |</el-button>
                        <el-button  @click="handleDelete(scope.$index, scope.row)"
                                   v-if="scope.row.isCpunt>0"
                                   v-hasPermission="200040003000"
                                   type="text"
                                    size="small"
                                   class="m-r-5">删除</el-button>
                    </template>
                </el-table-column>

            </el-table>
            <br>
            <div class="block">
                <el-row>
                    <el-col :span="24" class="text-right">
                       <el-pagination
                               @size-change="handleSizeChange"
                               @current-change="handleCurrentChange"
                               :current-page="currentPage"
                               :page-sizes="pageSizes"
                               :page-size="pageSize"
                               layout="total, sizes, prev, pager, next, jumper"
                               :total="total">
                       </el-pagination>
                    </el-col>
                </el-row>
            </div>
        </div>
      <PluginConfirm
        :show="dialogIsShow"
        @chooseSure="chooseSure()"
        @chooseCancel="chooseCancel()"
        @dialogResult="dialogResult">
      </PluginConfirm>
    </div>
</template>
<script>

    //注意路径
    export default{
        data(){
            return {
                tableData: [],
                loading:false,
              pageSizes:window.pageSizes,//所有可选择的条数
              pageSize:window.pageSize,//控制一页显示的条数
                currentPage:1,
                input:"",
                material:"",
                inputValue:"",
                total:0,
                searchValue:"&search.no_like=",
                hasCosts:"",
                dialogIsShow:false,
                curDataRow:null,
                curDataIndex:0
            }
        },
        created(){
            window.this = this;
            this.initData();
        },
        components: {

        },
        methods: {
            initData(){
                this.loading=true;
                this.currentPage=1;
                this.getData();
            },
            keyDown(ev){
                if(ev.keyCode==13) {
                    this.currentPage=1;
                    this.searchValue="&input="+this.input+"&material="+this.material;
                    this.getData();
                }
            },
            cleanSearch(){
                this.currentPage=1;
                this.input="";
                this.material="";
                this.hasCosts="";
                this.searchValue="&input="+this.input+"&material="+this.material;
                this.getData();
            },
            search(){
                this.currentPage=1;
                this.searchValue="&input="+this.input+"&material="+this.material;
                this.getData();

            },
            handleCurrentChange(currentPage){
                this.currentPage=currentPage;
                this.getData();
            },
            getData(){
                this.$axios.get("dishes/machiningRelations?page.pn="+this.currentPage+"&page.size="+this.pageSize+this.searchValue+"&hasCost="+this.hasCosts).then((data)=>{
                    if(data.status==200){
                        console.log(data.content.content)
                        this.tableData=data.content.content;
                        this.total=data.content.totalElements;
                        this.loading=false
                    }else{
                        this.loading=false
                    }
                })
            },
            /*用户选择提示框后处理*/
            dialogResult(param){
                this.dialogIsShow=param.close;
                if(param.choose==="ok"){
                    //console.log("确定");
                    var params = "";
                    this.$axios.delete("dishes/machiningRelations/destroy?id="+this.curDataRow.id).then(function(data){
                        if(data.body.status==200){
                            this.tableData.splice(this.curDataIndex,1);
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                            this.initData();
                        }else{
                            this.$message({
                                type: 'error',
                                message: data.body.message
                            });
                        }
                    })
                }else if(param.choose==="cancel"){
                    //console.log("取消");
                }else{
                    //console.log("不做处理");
                }
            },
            handleDelete(index, row) {
                this.curDataIndex = index;
                this.curDataRow = row;
                this.dialogIsShow = true;
                return false;
            },
            handleSizeChange(val){
                this.pageSize=val;
                this.getData();
            },

        }
    }
</script>
<style scoped>
    .seaTitle{
        line-height: 35px;
        text-align: right !important;
    }
    .el-button--text{
        color: #0a8cd2;
    }
</style>
